package com.loadmore.common.image

import android.content.Context
import android.os.Environment
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory
import com.bumptech.glide.module.AppGlideModule
import java.io.File

/**
 *@author sunleilei
 *@date 2018/7/12
 *@time 7:54
 *
 */

@GlideModule
class GlideModule : AppGlideModule() {
    override fun applyOptions(context: Context, builder: GlideBuilder) {
        super.applyOptions(context, builder)
        builder.setDiskCache(DiskLruCacheFactory(cacheFolder(context),1024*1024*100))
    }

    private fun cacheFolder(context: Context):String {
        if (Environment.isExternalStorageEmulated()) {
            return context.externalCacheDir.absolutePath+File.separator+"images"
        }else {
            return context.cacheDir.absolutePath+File.separator+"images"
        }
    }
}